<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue</title>
  <script src="../js/vue.js"></script>
  <script src="../js/vue-router.js"></script>
</head>
<body>
  <div id="app">
    <!-- 4.roter使用 跳转链接 加载组件的区域 -->
    <router-link to="/a">点击跳转A</router-link>
    <router-link to="/b">点击跳转B</router-link>
    <div>
      <!-- 加载组件的区域 -->
      <router-view></router-view>
    </div>
  </div>
  <script>
    // 1.组件定义
    let ComponentA = {
      template: `
        <div>组件A内容</div>
      `
    }
    let ComponentB = {
      template: `
        <div>组件B内容</div>
      `
    }
    // 2.路由的定义
    let router = new VueRouter({
      routes:[
        { path: '/', redirect: { name: 'aRouter'} },
        {
          path: '/a',
          component: ComponentA,
          beforeEnter(to,from,next) {
            console.log(to,from,next);
            next();
          }
        },
        // { path: '/a', name: 'aRouter', component: ComponentA, alias: '/A' },
        { path: '/b', name: 'bRouter', component: ComponentB },
      ]
    })
    // 全局路由守卫
    // 前置守卫
    // router.beforeEach((to,from,next) => {
    //   // console.log(to,from);
    //   next();
    // })
    // 后置守卫
    // router.afterEach((to,from,next) => {
    //   console.log(to,from);
    //   next();
    // })
    let vm = new Vue({
      el: '#app',
      // 3.组件内注册路由
      router: router,
      data: {

      }
    })
  </script>
</body>
</html>